package com.lh0811.forge.pserv.uacs.server.component.real_name_auth;

import com.lh0811.forge.dependency.basic_web.exception.CommonException;
import com.lh0811.forge.dependency.basic_web.response.ResponseStatus;
import com.lh0811.forge.dependency.basic_web.response.ServerResponse;
import com.lh0811.forge.dependency.security.client.component.SecurityUtil;
import com.lh0811.forge.dependency.security.core.model.entity.SecurityAuthority;
import com.lh0811.forge.pserv.uacs.server.repository.dao.UacsPlateUserDao;
import com.lh0811.forge.pserv.uacs.server.repository.entity.UacsPlateUser;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.stereotype.Component;

@Component
public class UserRealNameCheckHandler {

    @Resource
    private UacsPlateUserDao uacsPlateUserDao;

    public void check() throws Exception {
        SecurityAuthority securityAuthority = SecurityUtil.getSecurityAuthority();
        UacsPlateUser uacsPlateUser = uacsPlateUserDao.getById(Long.valueOf(securityAuthority.getUserId()));
        if (BooleanUtils.isFalse(uacsPlateUser.getRealNameFlag())) {
            throw CommonException.create(ServerResponse.createByError(ResponseStatus.NOT_REAL_NAME_ERROR.getCode(), "用户未实名认证"));
        }
    }
}
